/* 求a[j] - a[i]的最大值，其中j > i */

#include<iostream>
using namespace std;

int main(void)
{
	constexpr int N = 6;
	int a[N] = {5, 3, 1, 3, 4, 3};

	int minv = min(a[0], a[1]);
	int maxDiff = a[1] - a[0];

	int rj = a[1];
	int ri = a[0];
	for (int i = 2; i < N; i++)
	{
		int temp = a[i] - minv;
		if (temp > maxDiff)
		{
			maxDiff = temp;
			rj = a[i];
			ri = minv;
		}

		if (a[i] < minv)
		{
			minv = a[i];
		}
	}

	cout<< "The max diff is : "<< rj << " - " << ri << " = " << maxDiff <<endl;
}
